package logging

import (
	log "github.com/cihub/seelog"
)

//
// getConfigString
// @Description:
// @param logPah
// @return string
//
func getConfigString(logPah string) string {
	file := ""
	if logPah != "" {
		file =
			"        <filter levels=\"info,debug,error,critical\">\n" +
				"            <rollingfile type=\"size\" filename=\"" + file + "\" maxsize=\"102400\" maxrolls=\"5\"/>\n" +
				"        </filter>\n"
	}
	return "" +
		"<seelog type=\"sync\">\n" +
		"    <outputs formatid=\"main\">\n" +
		"        <console/>\n" +
		file +
		"    </outputs>\n" +
		"    <formats>\n" +
		"        <format id=\"main\" format=\"[%LEV][%Date(2006-01-02 15:04:05.999)][%File.%Line] %Msg%n\"/>\n" +
		"    </formats>\n" +
		"</seelog>"
}

//
// Initialize
// @Description:
//
func Initialize() {
	configString := getConfigString("")
	logger, err := log.LoggerFromConfigAsString(configString)
	if err != nil {
		return
	}
	err = log.ReplaceLogger(logger)
}
